﻿using System;
using System.Collections.Generic;
using System.IO;
using GalaxyTranslator.EntityDataModel;
using GalaxyTranslator.Presenters;
using GalaxyTranslator.ViewInterfaces;

namespace GalaxyTranslator.Client
{
    public partial class ClientOrderAdd : System.Web.UI.Page, IAddOrderView
	{
        private AddOrderPresenter _presenter;

        // Returns the name of the logged in user.
        public string MyselfName
        {
            get { return User.Identity.Name; }
        }

        public IList<Language> FromLanguages
        {
            set
            {
                DrpFromLang.DataSource = value; 
                DrpFromLang.DataBind();
            }
        }

        public IList<Language> ToLanguages
        {
            set
            {
                DrpToLang.DataSource = value;
                DrpToLang.DataBind();
            }
        }
        
        public string TextToTranslate
        {
            get
            {
                Stream content = FileUpload1.FileContent;
                StreamReader sr = new StreamReader(content);
                return sr.ReadToEnd();
            }
        }

        public int SelectedFromLanguageId
        {
            get { return int.Parse(DrpFromLang.SelectedValue); }
        }

        public int SelectedToLanguageId
        {
            get { return int.Parse(DrpToLang.SelectedValue); }
        }


        protected void Page_Load(object sender, EventArgs e)
		{
            InitView();
		}

        private void InitView()
        {
            _presenter=new AddOrderPresenter(this);
            _presenter.InitView(IsPostBack);
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            _presenter.AddOrder();
        }
	}
}